home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#18 (Mar 87)
/
Printer LSP sources
/
PrintTest Main.TXT
< prev
next >
Wrap
Text File
|
1987-02-13
|
5KB
|
229 lines
PROGRAM PrintTest;
{$I-}
{ Examine and display TPrint record values.}
{ Written by Joel West , Western Software Technology}
{ LS Pascal source conversion by D. Smith }
{Begun with an underlying skeleton , using part of }
{an example from Apple User Education}
{File : Example code for a text editor by Cary Clark , }
{Macintosh Technical Support Version 1.1 May 13 , 1985 }
{Portions copyright © 1986 by}
{ Joel West , Western Software Technology,}
{ for MacTutor. }
{ A document in this program (built using TextEdit) is used to}
{ display the contents of a modified TPrint record.}
{ There are Job and Style dialogs for modifying the record, and}
{ for actually printing out the document.}
USES
MacPrint, MyGlobals, StringFormat, DumpTPrint, Windows, Printing, SetupMenus;
{------------Alert for About…------------------}
PROCEDURE AboutThisProgram;
VAR
itemhit : INTEGER;
hand : StringHandle;
BEGIN
DialogueDeactivate;
hand := GetString(STR_id);
ParamText(hand^^, '', '', '');
itemhit := NoteAlert(ALRT_about, NIL);
END; {AboutThisProgram}
{---------------Handle menu command------------}
PROCEDURE DoCommand (commandkey : BOOLEAN);
VAR
daname : Str255;
refnum, theMenu, theItem : INTEGER;
menuResult : LONGINT;
daedit : BOOLEAN;
BEGIN
IF commandkey THEN
menuResult := MenuKey(theChar)
ELSE
menuResult := MenuSelect(myEvent.where);
theMenu := HiWord(menuResult);
theItem := LoWord(menuResult);
CASE theMenu OF
appleMenu :
BEGIN
IF theItem = 1 THEN
AboutThisProgram
ELSE
BEGIN
GetItem(myMenus[appleMenu], theItem, daname);
refNum := OpenDeskAcc(daname)
END
END;
fileMenu :
BEGIN
CASE theItem OF
newItem : {New }
OpenAWindow;
closeItem : {Close }
CloseAWindow;
stlItem : {PrStlDialog… }
BEGIN
PrOpen;
DialogueDeactivate;
IF PrStlDialog(wdh^^.theTHP) THEN
DumpPrint('After PrintStlDialog(…)', wdh^^.theTHP);
PrClose
END;
jobItem : {PrJobDialog… }
BEGIN { just modifying TPrint, not actually printing }
PrOpen;
DialogueDeactivate;
IF PrJobDialog(wdh^^.theTHP) THEN
DumpPrint('After PrJobDialog(…)', wdh^^.theTHP);
PrClose
END;
setupItem : {Page Setup… }
BEGIN
PrOpen;
DialogueDeactivate;
IF PrStlDialog(PrintHdl) THEN
BEGIN
END;
PrClose
END;
printItem : {Print }
printFlag := TRUE; {Do it after segs unloaded}
quitItem : {Quit }
doneFlag := TRUE;
OTHERWISE {required for LSP!}
BEGIN
END;
END {CASE theItem}
END; {fileMenu}
editMenu :
daedit := SystemEdit(theitem - 1);
OTHERWISE
BEGIN
END;
END; {CASE theMenu}
HiLiteMenu(0);
END; {DoCommand}
{---------------The main event loop--------------}
PROCEDURE MainEventLoop;
VAR
tempwindow : WindowPtr; {the find window}
BEGIN
REPEAT
SystemTask;
IF printFlag THEN
BEGIN
PrOpen;
DoPrinting;
PrClose
END;
IF GetNextEvent(everyEvent, myEvent) THEN
BEGIN
CASE myEvent.what OF
mouseDown :
BEGIN
CASE FindWindow(myEvent.where, tempwindow) OF
inMenuBar :
DoCommand(FALSE);
inSysWindow :
SystemClick(myEvent, tempwindow);
inDrag :
DragWindow(tempwindow, myEvent.where, dragRect);
inContent :
SysBeep(1);
inGoAway :
IF TrackGoAway(tempwindow, myEvent.where) THEN
CloseAWindow;
OTHERWISE
BEGIN
END;
END {CASE FindWindow }
END; {of mouseDown }
keyDown, autoKey :
BEGIN
theChar := CHR(BitAnd(myEvent.message, charCodeMask));
IF BitAnd(myEvent.modifiers, CmdKey) <> 0 THEN
DoCommand(TRUE) { do menu equivalent }
ELSE
SysBeep(1); { no typing allowed! }
END; {of keyDown}
activateEvt :
MyActivate;
updateEvt :
DrawWindow;
OTHERWISE
BEGIN
END;
END; {CASE Event.what }
CheckWindowMode;
END {of true GetNextEvent}
ELSE IF (myEvent.what = nullEvent) AND doneFlag AND (FrontWindow <> NIL) THEN
CloseAWindow;
{ We like to leave lots of memory available, so unload everything as a precaution }
UnloadSeg(@SWrite); {segment StringFormat}
UnloadSeg(@PrintLine); {segment DumpTPrint}
UnloadSeg(@OpenAWindow); {segment Windows}
UnloadSeg(@DoPrinting); {segment Printing}
UNTIL doneFlag AND (FrontWindow = NIL);
END;
{-------- crash recovery ---------------}
PROCEDURE crash;
BEGIN
ExitToShell;
END;
{-------------Memory initialization & Setup ---------}
PROCEDURE SetUpMemory;
BEGIN
InitGraf(@thePort);
InitFonts;
InitWindows;
InitMenus;
TEInit;
InitDialogs(@crash);
InitCursor;
MaxApplZone;
MoreMasters;
MoreMasters;
MoreMasters;
MoreMasters;
FlushEvents(everyEvent, 0);
watchHdl := GetCursor(WatchCursor);
HNoPurge(Handle(watchHdl));
printHdl := THPrint(NewHandle(SizeOf(TPrint)));
PrOpen;
PrintDefault(printHdl); { the one used for actual printing }
PrClose;
Linebuff := ''; {required for LSP}
END;
{-------------Main program-------------}
BEGIN {main program }
SetUpMemory;
SetUpMenus;
SetUpWindow;
unloadseg(@SetUpMenus);
MainEventLoop;
SetCursor(watchHdl^^);
END. {main}